package com.order.server.service;

import com.order.server.mapper.OrderMapper;
import com.order.server.model.OrderInfo;
import com.order.server.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper ;
    @Autowired
    private RestTemplate restTemplate ;

    public OrderInfo getById(Integer orderId) {

        OrderInfo orderInfo = orderMapper.getById(orderId);

        // 构造url,就是获取 product数据是的地址         从 orderinfo里获取 productid
        String url = "http://product-server/product/"+ orderInfo.getProductId() ;
        // 通过远程调用访问这个url , 来获取 productInfo对象
        ProductInfo productInfo = restTemplate.getForObject(url, ProductInfo.class);
        orderInfo.setProductInfo(productInfo);
        return orderInfo;
    }
}
